<?php
/**
 * App端 商品详情
 * Author: lyun
 * Date: 2018/11/19
 * Created by Panxsoft.
 */


namespace App\Http\Controllers\Api\V1\App\Product;

use App\Http\Controllers\ApiController;
use App\Http\Requests\Products\ShowProductDetailRequest;
use App\Http\Requests\Products\ShowProductReviewRequest;
use App\Http\Services\Api\V1\App\Product\ProductDetailService;
use App\Models\Currency;
use App\Models\Products\Product;
use App\Models\Store;
use Illuminate\Http\Request;

class ProductDetailController extends ApiController
{
    public $product_detail;

    public function __construct()
    {
        $this->product_detail = new ProductDetailService;
    }

    /**
     * App端 展示商品详情的基本数据
     *
     * @param ShowProductDetailRequest $request
     * @return array|\Illuminate\Http\Response
     * @throws \Exception
     */
    public function show(ShowProductDetailRequest $request)
    {
        $product_id = $request->product_id;

        /** @var Currency $currency */
        $currency = Currency::fromEnv();

       $product_detail = $this->product_detail->getProductDetail($currency, $product_id);

       return $this->response(compact('product_detail'));
    }

    /**
     * App端 展示商品详情的选项属性值
     *
     * @param ShowProductDetailRequest $request
     * @return array|\Illuminate\Http\Response
     * @throws \Exception
     */
    public function indexSpec(ShowProductDetailRequest $request)
    {
        $product_id = $request->product_id;

        /** @var Currency $currency */
        $currency = Currency::fromEnv();

        $product_specs = $this->product_detail->getProductSpec($currency, $product_id);

        return $this->response($product_specs);
    }

    /**
     *  app端 返回商品详情页评论信息
     *
     * @param ShowProductReviewRequest $request
     * @return array|\Illuminate\Http\Response
     * @throws \Exception
     */
    public function indexReviews(ShowProductReviewRequest $request)
    {
        $product_reviews = $this->product_detail->getProductReviews($request);

        return $this->response(compact('product_reviews'));
    }
}
